<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13.元素offset</title>
    <style>
        *{
            margin: 0;
            padding: 0;

        }
        body{
            height: 2000px;
        }
        .box1{
            position: relative;
            top: 30px;
            left: 30px;
            margin-top: 300px;
            margin-left: 100px;
            width: 300px;
            height: 300px;
            background-color: aqua;
            border: solid 10px red;
        }
        .box{
            position: relative;
            top: 50px;
            background-color: blueviolet
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1">

        </div>
    </div>
</body>
<script>
    var box1=document.getElementsByClassName('box1')[0]
    //获取元素距离浏览器左上角偏移量(只读)当父元素
    console.log(box1.offsetTop,box1.offsetLeft)

    //获取边框盒的宽高（包括边框+内边距+内容宽高）（只读）
    console.log(box1.offsetWidth,box1.offsetHeight)
    //获取相对定位的父元素
    console.log(box1.offsetParent)
</script>
</html>